import { App } from 'vue'
import { ElMessage } from 'element-plus'

export const btnAntiShake = (app: App<Element>) => {
    app.directive('btnAntiShake', {
        // mounted(el, binding) {
        //     let timer: any = null
        //     let count: number = 0

        //     el.addEventListener('click', () => {
        //         if (!el.disabled) {
        //             el.disabled = true
        //             count++
        //             if (count > 2) {
        //                 ElMessage.success('亲，慢点！')
        //                 count = 0
        //             }
        //             timer = setTimeout(() => {
        //                 el.disabled = false

        //                 clearTimeout(timer)
        //             }, binding.value)
        //         }
        //     })
        // },
        mounted(el, binding) {
            let timer: any

            el.addEventListener('click', () => {
                clearTimeout(timer)
                timer = setTimeout(() => {
                    console.log(binding.value)
                }, binding.value)

            })
        }
    })
}
